"""
订阅相关的Pydantic模型
"""

from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
from decimal import Decimal


class SubscriptionCreate(BaseModel):
    """创建订阅模型"""
    keyword: str = Field(..., min_length=1, max_length=100, description="搜索关键词")
    min_price: Optional[Decimal] = Field(None, ge=0, description="最低价格")
    max_price: Optional[Decimal] = Field(None, ge=0, description="最高价格")
    category: Optional[str] = Field(None, max_length=50, description="商品分类")
    condition: Optional[str] = Field(None, max_length=50, description="商品状态")
    duration_days: int = Field(default=1, ge=1, le=30, description="监控天数")


class SubscriptionUpdate(BaseModel):
    """更新订阅模型"""
    keyword: Optional[str] = Field(None, min_length=1, max_length=100, description="搜索关键词")
    min_price: Optional[Decimal] = Field(None, ge=0, description="最低价格")
    max_price: Optional[Decimal] = Field(None, ge=0, description="最高价格")
    category: Optional[str] = Field(None, max_length=50, description="商品分类")
    condition: Optional[str] = Field(None, max_length=50, description="商品状态")
    is_active: Optional[bool] = Field(None, description="是否激活")


class SubscriptionResponse(BaseModel):
    """订阅响应模型"""
    id: int
    user_id: int
    keyword: str
    min_price: Optional[Decimal] = None
    max_price: Optional[Decimal] = None
    category: Optional[str] = None
    condition: Optional[str] = None
    is_active: bool
    created_at: datetime
    updated_at: datetime
    expires_at: datetime
    
    class Config:
        from_attributes = True


class SubscriptionListResponse(BaseModel):
    """订阅列表响应模型"""
    subscriptions: list[SubscriptionResponse]
    total: int
    page: int
    page_size: int


class SubscriptionStats(BaseModel):
    """订阅统计模型"""
    total_subscriptions: int
    active_subscriptions: int
    expired_subscriptions: int
    total_notifications: int
